<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form">
                <div class="layui-form lay-header">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">任务单编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="code" class="layui-input" type="text"
                                                   placeholder="任务单编号"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">收货仓：</label>
                                        <div class="layui-input-inline">
                                            <select name="warehouseId">
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">创建时间：</label>
                                        <div class="layui-input-inline">
                                            <input id="pTime" class="layui-input date-icon" type="text"
                                                   placeholder="选择创建时间" autocomplete="off" readonly/>
                                        </div>
                                        <input name="startCreateTime" id="sTime" style="display: none"/>
                                        <input name="endCreateTime" id="eTime" style="display: none"/>
                                    </div>
                                    <div class="layui-inline">
                                        <button type="button" class="layui-btn icon-btn color-green"
                                                lay-filter="formSubSearchLog" lay-submit>查询
                                        </button>
                                        <button type="reset" class="layui-btn icon-btn color-white" lay-filter="resets"
                                                lay-submit>重置
                                        </button>
                                    </div>
                                </div>
                                <div class="query-rt"></div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button type="button" id="storageSignAdd" class="layui-btn icon-btn color-reseda">
                                    添加签收单
                                </button>
                            </div>
                            <div class="lay-btn-rt">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="storageSignTable" lay-filter="storageSignTable"></table>
        </div>
    </div>
</div>

<style>
    .companyFormClass .open-details-box {
        padding: 20px;
    }

    .companyFormClass .open-details-box input {
        border: none !important;
        color: #666;
    }
</style>

<script type="text/html" id="storageSignTableBar">

</script>

<!--签收表格操作列-->
<script type="text/html" id="signInfoDetailTableBar">
    {{# if(d.status=="created"){  }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="signed">签收</a>
    {{# }else if(d.status =="signed"){ }}
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    {{# } }}
</script>

<!--详情弹窗-->
<script type="text/html" id="productStorageSignDetailForm">
    <form lay-filter="productStorageSignDetailForm" class="layui-form model-form companyFormClass">
        <div class="open-details-box" style="height: 100%;">
            <div class="layui-form-item">
                <label class="layui-form-label">单据编号</label>
                <div class="layui-input-inline">
                    <input name="code" type="text" class="layui-input red" readonly="readonly"/>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-md5">
                    <div class="layui-form-item">
                        <div class="open-details-title">来往信息</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发货商</label>
                        <div class="layui-input-inline">
                            <input value="湖南云端商业管理有限公司" type="text" class="layui-input red"
                                   readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">出货仓库</label>
                        <div class="layui-input-inline">
                            <input name="entWarehouseName" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发货人</label>
                        <div class="layui-input-inline">
                            <input name="consigner" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发货时间</label>
                        <div class="layui-input-inline">
                            <input name="sendTime" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">目标仓库</label>
                        <div class="layui-input-inline">
                            <input name="inWarehouseName" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品描述</label>
                        <div class="layui-input-inline">
                            <input name="remark" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md5 layui-col-md-offset2">
                    <div class="layui-form-item">
                        <div class="open-details-title">物流信息</div>
                    </div>
                    <div class="layui-form-item transportType" style="display: none;">
                        <label class="layui-form-label">物流单号</label>
                        <div class="layui-input-inline">
                            <input name="expressCode" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item transportType" style="display: none;">
                        <label class="layui-form-label">物流企业</label>
                        <div class="layui-input-inline">
                            <input name="logisticsCompany" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">运输方式</label>
                        <div class="layui-input-inline">
                            <input name="transportTypeDesc" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">车牌号</label>
                        <div class="layui-input-inline">
                            <input name="carNo" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-inline">
                            <input name="customerConcat" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-inline">
                            <input name="customerMoble" type="text" class="layui-input" readonly="readonly"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="open-details-title">入库商品</div>
                <table class="layui-table" id="productStorageSignDetailTable"
                       lay-filter="productStorageSignDetailTable"></table>
            </div>
        </div>
    </form>
</script>

<!-- 入库签收单弹窗 -->
<script type="text/html" id="storageSignAddForm">
    <form lay-filter="storageSignAddForm" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto" style="padding-top: 5px;">
                <div class="layui-row table-bor">
                    <table class="layui-table" id="signShowDetailTable" lay-filter="signShowDetailTable"></table>
                </div>
                <div class="layui-row isSelectCode table-bor scroll-table-4" style="margin-top: 15px;display: none;">
                    <div class="layui-col-md4">
                        <div class="layui-form-item">
                            <div class="open-details-title">签收订单信息</div>
                        </div>
                        <table class="layui-table" id="storageSignInfoDetailTable"
                               lay-filter="storageSignInfoDetailTable"></table>
                    </div>
                    <div class="layui-col-md8 scroll-table-4" style="padding-left: 25px">
                        <div class="layui-form-item">
                            <div class="open-details-title">签收物资</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-auto">扫描包装编码</label>
                            <div class="layui-input-inline" style="width: 260px;">
                                <input name="workBinCode" type="text" class="layui-input workBinCode"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn icon-btn color-green" id="scanWorkBinCode"
                                        lay-filter="scanWorkBinCode" lay-submit>确定
                                </button>
                            </div>
                        </div>
                        <table class="layui-table" id="signInGoodsTable" lay-filter="signInGoodsTable"></table>
                    </div>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button class="layui-btn" lay-filter="storageSignAddFormSubmit" lay-submit>保存</button>
            </div>
        </div>
    </form>
</script>

<!-- 选择入库计划编号 -->
<script type="text/html" id="selectStorageSignListAdd">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">入库计划编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="code" class="layui-input" type="text" style="width: 240px;"
                                       placeholder="入库计划编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="selectStorageSignListAddFormSubSearchLog"
                                    lay-submit>搜索
                            </button>
                            <button id="selectStorageSignListAddClose" class="layui-btn icon-btn">确认选择</button>
                        </div>
                    </div>
                </div>

                <!-- 表格 -->
                <table class="layui-table" id="selectStorageSignListAddTable"
                       lay-filter="selectStorageSignListAddTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var laydate = layui.laydate;
        var admin = layui.admin;

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    let dateValue = value.split(" - ");
                    $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
                    $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
                } else {
                    $("input[name='startCreateTime']").val("");
                    $("input[name='endCreateTime']").val("");
                }
            }
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#storageSignTable',
            url: config.base + 'enterprisecab/order/admin/storageSign/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                , {field: 'code', align: 'center', title: '签收任务单编号', width: 180}
                , {field: 'inoutTypeName', align: 'center', title: '入库类型'}
                , {field: 'planCode', align: 'center', title: '所属计划单号', width: 160}
                , {field: 'productionMachine', align: 'center', title: '发货来源'}
                , {field: 'feedingPeople', align: 'center', title: '发货人'}
                , {field: 'productNum', align: 'center', title: '发货商品数'}
                , {field: 'warehouseName', align: 'center', title: '入库目标仓库'}
                , {field: 'creatorName', align: 'center', title: '签收人'}
                , {field: 'statusDesc', align: 'center', title: '状态'}
                , {field: 'createTime', align: 'center', title: '创建时间', width: 160}
                // , {align: 'center', toolbar: '#storageSignTableBar', title: '操作'}
            ]],
            done: function (res, curr, count) {

            }
        });

        // option渲染
        function loadSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].productType}'>${data[i].name}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 3) {
                    html += `<option value='${data[i].id}'>${data[i].warehouseName}</option>`;
                } else if (type == 4) {
                    html += `<option value='${data[i].skuCode}'  skuCode='${data[i].skuCode}'>${data[i].skuName}</option>`;
                } else if (type == 5) {
                    html += `<option value='${data[i].skuCode}'>${data[i].skuName}</option>`;
                } else if (type == 6) {
                    html += `<option value='${data[i].code}'>${data[i].name}</option>`;

                }
            }
            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        //查询仓库
        admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0) {
                    loadSelectHtml(res.data, "选择收货仓", "warehouseId", 2);
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');

        // 工具条点击事件
        table.on('tool(storageSignTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') { //详情
                // showDetailModel(data);
            }
        });

        //监听排序
        table.on('sort(storageSignTable)', function (obj) {
            table.reload('storageSignTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        //渲染下拉框
        form.render('select');

        // 显示详情弹窗
        function showDetailModel(data) {
            admin.open({
                type: 1,
                isDetail: true,
                area: '1300px',
                offset: '65px',
                title: '云仓入库单详情',
                content: $('#productStorageSignDetailForm').html(),
                success: function () {
                    let deliverProductArr = [];
                    if (data.transportType == 'self') {
                        $(".transportType").hide();
                    } else {
                        $(".transportType").show();
                    }
                    // 查询入库商品信息
                    admin.req('platform/order/admin/inventoryInoutJob/getInventoryJobProductList', {jobId: data.id}, function (res) {
                        if (res.code == 200) {
                            deliverProductArr = res.data;
                            table.reload('productStorageSignDetailTable', {
                                data: deliverProductArr,
                            })
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    var productStorageSignDetailTable = table.render({
                        elem: '#productStorageSignDetailTable',
                        data: deliverProductArr,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'number', title: '序号', width: 60, type: 'numbers'}
                            , {field: 'id', title: 'ID', width: 60, hide: true}
                            , {field: 'skuCode', sort: true, title: '物料编号', width: 150}
                            , {
                                field: 'skuPic',
                                sort: true,
                                title: '图片',
                                width: 120,
                                templet: '<div><img  src="{{ d.skuPic }}"></div>'
                            }
                            , {field: 'productName', sort: true, title: '物料名称', width: 150}
                            , {field: 'skuSpecCode', title: '规格', width: 150}
                            , {field: 'enterpriceCode', title: '企业货号'}
                            , {field: 'barcode', title: '国标条码'}
                            , {field: 'total', title: '平台结算价'}
                            , {field: 'quantity', title: '入库数量', width: 120}
                            , {field: 'unitName', title: '最小单位'}
                            , {field: 'totalMoney', title: '总金额'}
                        ]]
                        , done: function (res, curr, count) {

                        }
                    });

                    form.val('productStorageSignDetailForm', data);
                }
            });
        }

        // 添加入库签收单
        $("#storageSignAdd").click(function () {
            storageSignAddShow();
        });

        // 添加签收
        function storageSignAddShow() {
            var storageSignOpen = admin.open({
                type: 1,
                area: ['82%', '90%'],
                title: '添加生产入库签收单',
                content: $('#storageSignAddForm').html(),
                success: function () {
                    let detailData = [{}];
                    let cabinetLoadPlan = {};
                    let jobProductId = '', planId = '';
                    let signInGoodsData = [];
                    // 详情列表
                    var insTb2 = table.render({
                        elem: '#signShowDetailTable',
                        data: detailData,
                        limit: detailData.limit,
                        cellMinWidth: 120,
                        page: false,
                        cols: [[
                            {
                                field: 'code',
                                align: 'center',
                                title: '入库计划编号',
                                templet: '<div><span class="distCode" style="display: block;cursor: pointer;" data-add="{{d.code != null ? false : true}}">{{d.code != null ? d.code : "请选择入库计划编号"}}</span></div>'
                            }
                            , {field: 'productionMachine', title: '发货来源', align: 'center'}
                            , {field: 'feedingPeople', title: '发货人', align: 'center'}
                            , {field: 'productNum', title: '商品数量', align: 'center'}
                            , {field: 'warehouseName', title: '入库云仓', align: 'center'}
                            , {field: 'areaName', title: '仓库所在地', align: 'center'}
                            , {field: 'createTime', title: '创建时间', align: 'center', width: '160'}
                        ]],
                        done: function () {
                            // 选择所属配货需求订单
                            $(".distCode").click(function () {
                                // 获取入库签收单数据
                                var distCodeList = admin.open({
                                    type: 1,
                                    title: '配货订单列表',
                                    area: ['75%', '90%'],
                                    content: $('#selectStorageSignListAdd').html(),
                                    success: function () {
                                        form.render("select");

                                        // 渲染表格
                                        var selectStorageSignListAddTable = table.render({
                                            elem: '#selectStorageSignListAddTable',
                                            url: config.base + 'enterprisecab/order/admin/storageSign/getStoragePlanAll',
                                            page: true,
                                            cellMinWidth: 100,
                                            cols: [[
                                                {type: 'radio'}
                                                , {field: 'code', align: 'center', title: '入库计划编号', width: 240}
                                                , {field: 'productionMachine', title: '发货来源', align: 'center'}
                                                , {field: 'feedingPeople', title: '发货人', align: 'center'}
                                                , {field: 'productNum', title: '商品数量', align: 'center'}
                                                , {field: 'warehouseName', title: '入库云仓', align: 'center'}
                                                , {field: 'areaName', title: '仓库所在地', align: 'center'}
                                                , {field: 'createTime', title: '创建时间', align: 'center'}
                                            ]],
                                        });

                                        // 搜索
                                        form.on('submit(selectStorageSignListAddFormSubSearchLog)', function (data) {
                                            selectStorageSignListAddTable.reload({
                                                where: data.field,
                                                page: {curr: 1}
                                            }, 'data');
                                        });

                                        // 确认选择
                                        $('#selectStorageSignListAddClose').click(function () {
                                            var checkStatus = table.checkStatus('selectStorageSignListAddTable'); //test即为基础参数id对应的值
                                            var dataS = checkStatus.data;

                                            if (checkStatus.data.length == 0) {
                                                layer.msg("请选择入库需求单", {icon: 2, time: 1000});
                                            } else {
                                                cabinetLoadPlan.distributionDemandId = dataS[0].id;
                                                layer.close(distCodeList);
                                                detailData[0].code = dataS[0].code;
                                                detailData[0].productionMachine = dataS[0].productionMachine;
                                                detailData[0].feedingPeople = dataS[0].feedingPeople;
                                                detailData[0].productNum = dataS[0].productNum;
                                                detailData[0].warehouseName = dataS[0].warehouseName;
                                                detailData[0].areaName = dataS[0].areaName;
                                                detailData[0].createTime = dataS[0].createTime;

                                                // 获取数据集合并传入回显
                                                table.reload('signShowDetailTable', {
                                                    data: detailData,
                                                    limit: detailData.length
                                                });
                                                $(".isSelectCode").show();
                                                planId = dataS[0].id;
                                                storageSignTableShow(planId);
                                                // 清空数据
                                                $("input[name='workBinCode']").val('');
                                                signInGoodsData = [];
                                                table.reload('signInGoodsTable', {
                                                    data: signInGoodsData,
                                                })
                                            }
                                        });
                                    }
                                })
                            })
                        }
                    });

                    function storageSignTableShow(id) {
                        // 签收订单信息
                        var storageSignInfoDetailTable = table.render({
                            elem: '#storageSignInfoDetailTable',
                            url: config.base + 'enterprisecab/order/admin/storageSign/getInventorySignProduct',
                            where: {planId: id},
                            cellMinWidth: 100,
                            cols: [[
                                {field: 'number', width: 40, type: 'numbers'}
                                , {field: 'skuCode', title: '物料编号', align: 'center', width: 130}
                                , {field: 'productName', title: '物料名称', align: 'center', width: 120}
                                , {field: 'receivableQuantity', title: '应收数', align: 'center'}
                                , {field: 'packLabeQuantity', title: '已签收数', align: 'center'}
                            ]]
                        });

                        table.on('row(storageSignInfoDetailTable)', function (obj) {
                            jobProductId = obj.data.id
                            getProductPackLabelSign(jobProductId)
                        });

                        // 查询已签收的物资
                        function getProductPackLabelSign(id) {
                            layer.load(2);
                            admin.req('enterprisecab/order/admin/storageSign/getInventorySignPackLabel', {jobProductId: id}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    signInGoodsData = res.data;
                                    signInGoodsData.forEach((item, index) => {
                                        signInGoodsData[index].status = 'fulfill'
                                    })
                                    table.reload('signInGoodsTable', {
                                        data: signInGoodsData,
                                    })
                                } else {
                                    signInGoodsData = [];
                                    table.reload('signInGoodsTable', {
                                        data: signInGoodsData,
                                    })
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                        }

                        // 扫描料箱包装码
                        form.on('submit(scanWorkBinCode)', function (d) {
                            let code = $("input[name='workBinCode']").val();
                            if (code == '') {
                                layer.msg('请输入物料包装编码', {icon: 2});
                                return false;
                            }
                            let filterList = signInGoodsData.filter((item) => {
                                return item.packLabeCode == code;
                            });

                            if (filterList.length > 0) {
                                layer.msg('包装码已存在', {icon: 2});
                                return false;
                            }
                            getProductPackLabelByCode(code);
                            return false;
                        });

                        // 查询物料包装码
                        function getProductPackLabelByCode(code) {
                            layer.load(2);
                            admin.req('enterprise/product/admin/productPackLabel/getPackLabelVOByCode',
                                {planId: planId, code: code, type: 2}, function (res) {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        let packLabelData = res.data;
                                        packLabelData.packLabeQuantity = packLabelData.quantity;
                                        packLabelData.abnormalQuantity = 0;
                                        packLabelData.packLabeCode = packLabelData.code;
                                        if (jobProductId != '') {
                                            jobProductId = '';
                                            signInGoodsData = [];
                                        }

                                        signInGoodsData.push(res.data);

                                        table.reload('signInGoodsTable', {
                                            data: signInGoodsData,
                                        });
                                        // 清空input
                                        $("input[name='workBinCode']").val('');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'GET');
                        }

                        // 签收物资表格
                        var signInGoodsTable = table.render({
                            elem: '#signInGoodsTable',
                            data: signInGoodsData,
                            cellMinWidth: 120,
                            cols: [[
                                {field: 'number', title: '序号', width: 50, type: 'numbers'}
                                , {field: 'packLabeCode', title: '包装码', align: 'center'}
                                , {field: 'skuCode', title: '所属SKU', align: 'center'}
                                , {field: 'packName', title: '包装规格', align: 'center'}
                                , {field: 'quantity', title: '配送数', align: 'center'}
                                , {
                                    field: 'packLabeQuantity', title: '签收数', align: 'center', templet: function (d) {
                                        if (d.status == 'signed' || d.status == 'fulfill') {
                                            return '<span>' + d.packLabeQuantity + '</span>'
                                        } else {
                                            return '<input signId="' + d.id + '" class="layui-input packLabeQuantity" style="height: 28px;" type="text" ' +
                                                'value="' + d.packLabeQuantity + '" />'
                                        }
                                    }
                                }
                                , {
                                    field: 'abnormalQuantity', title: '异常数', align: 'center', templet: function (d) {
                                        if (d.status == 'signed' || d.status == 'fulfill') {
                                            return '<span>' + d.abnormalQuantity + '</span>'
                                        } else {
                                            return '<input signId="' + d.id + '" class="layui-input abnormalQuantity" style="height: 28px;" type="text" ' +
                                                'value="' + d.abnormalQuantity + '" />'
                                        }
                                    }
                                }
                                , {field: 'statusDesc', title: '状态', align: 'center', width: '100'}
                                , {align: 'center', toolbar: '#signInfoDetailTableBar', title: '操作'}
                            ]],
                        });

                        // 监听签收数
                        $("body").delegate(".packLabeQuantity", "change", function () {
                            let id = $(this).attr('signId');
                            let reg = /^[1-9]+[0-9]*$/;
                            let packLabeQuantity = $(this).val();
                            signInGoodsData.forEach((item, index) => {
                                if ((item.id === id)) {
                                    let quantity = parseInt(item.quantity);
                                    if (!reg.test(packLabeQuantity)) {
                                        layer.msg('请输入正确的数字', {icon: 2});
                                        packLabeQuantity = quantity;
                                        $(this).val(packLabeQuantity);
                                    }
                                    if (parseInt(packLabeQuantity) > quantity) {
                                        layer.msg('签收数量不能大于应收数量', {icon: 2});
                                        packLabeQuantity = quantity;
                                        $(this).val(packLabeQuantity);
                                        $(this).parents('td').siblings().find('.abnormalQuantity').val(0);
                                        return false;
                                    }
                                    let abnormalQuantity = quantity - packLabeQuantity
                                    $(this).parents('td').siblings().find('.abnormalQuantity').val(abnormalQuantity);
                                }
                            })
                        });

                        // 监听异常数量
                        $("body").delegate(".abnormalQuantity", "change", function () {
                            let id = $(this).attr('signId');
                            let reg = /^[1-9]+[0-9]*$/;
                            let abnormalQuantity = $(this).val();
                            signInGoodsData.forEach((item, index) => {
                                if ((item.id === id)) {
                                    let quantity = parseInt(item.quantity);
                                    if (!reg.test(abnormalQuantity)) {
                                        layer.msg('请输入正确的数字', {icon: 2});
                                        abnormalQuantity = 0;
                                        $(this).val(abnormalQuantity);
                                    }
                                    if (parseInt(abnormalQuantity) > quantity) {
                                        layer.msg('异常数量不能大于应收数量', {icon: 2});
                                        abnormalQuantity = 0;
                                        $(this).val(abnormalQuantity);
                                        $(this).parents('td').siblings().find('.packLabeQuantity').val(quantity);
                                        return false;
                                    }
                                    let packLabeQuantity = quantity - abnormalQuantity;
                                    $(this).parents('td').siblings().find('.packLabeQuantity').val(packLabeQuantity);
                                }
                            })
                        });

                        // 工具条点击事件
                        table.on('tool(signInGoodsTable)', function (obj) {
                            var data = obj.data;
                            if (obj.event === 'signed') { // 签收
                                let packLabeQuantity = $(this).parents('td').siblings().find('.packLabeQuantity').val(); //签收数
                                let abnormalQuantity = $(this).parents('td').siblings().find('.abnormalQuantity').val(); //异常数
                                signInGoodsData.forEach((item, index) => {
                                    if ((data.id === item.id)) {
                                        signInGoodsData[index].packLabeQuantity = packLabeQuantity;
                                        signInGoodsData[index].abnormalQuantity = abnormalQuantity;
                                        signInGoodsData[index].status = 'signed';
                                        signInGoodsData[index].statusDesc = '已签收';
                                    }
                                });
                            } else if (obj.event === 'edit') { //修改
                                signInGoodsData.forEach((item, index) => {
                                    if ((data.id === item.id)) {
                                        signInGoodsData[index].status = 'created';
                                        signInGoodsData[index].statusDesc = '已创建';
                                    }
                                });
                            }
                            console.log(signInGoodsData);
                            table.reload('signInGoodsTable', {
                                data: signInGoodsData,
                            });
                        });

                        // 表单提交
                        form.on('submit(storageSignAddFormSubmit)', function (d) {
                            if (signInGoodsData.length == 0) {
                                layer.msg('签收物资不能为空', {icon: 2});
                                return false;
                            }
                            let paramData = [];
                            signInGoodsData.forEach((item, index) => {
                                if (item.status != 'fulfill' && item.status != 'created') {
                                    paramData.push(item)
                                }
                            });
                            if (paramData.length == 0) {
                                layer.msg('请先签收物资', {icon: 2});
                                return false;
                            }
                            layer.load(2);
                            admin.req('enterprisecab/order/admin/storageSign/packLabelSign', JSON.stringify(paramData), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    // 清空签收数据
                                    table.reload('storageSignTable');
                                    layer.close(storageSignOpen);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8');
                            return false;
                        });
                    }
                }
            });
        }
    });
</script>